'''
Created on Oct 26, 2012

@author: All

Define the variables that are used by other modules. e.g. DB pool, and memcache connection
'''

import os, oursql, pylibmc
from DBUtils.PooledDB import PooledDB

################################# config params #################################
SERVER_KEY = "cb5cdc488623365a8bfb1c68e689a8db"
HTTP_HEAD_PARAM_NAME = 'ALERT'
LOG_LEVEL = 'DEBUG'
SYS_LOG_LEVEL = 'NOLOG'

HOST_SERVER = "http://10.197.84.239/MM"
IMG_SERVER = "http://10.197.84.239/MM/static"

MASTER_DB_ADDR = "10.197.84.222"
MASTER_DB_PORT = 3306
MASTER_DB_NAME = "MobileMoney"
MASTER_USER = "emma_dev"
MASTER_PASSWD = "mstr123"
MASTER_MAX_CONN = 10

SLAVE_DB_ADDR = "10.197.84.223"
SLAVE_DB_PORT = 3306
SLAVE_DB_NAME = "MobileMoney"
SLAVE_USER = "emma_dev"
SLAVE_PASSWD = "mstr123"
SLAVE_MAX_CONN = 10

MEMCACHE_ADDR = "127.0.0.1:72345"
ONLINE_MEMCACHE_ADDR = "127.0.0.1:12346"

MAIL_SERVER_ADDR = "10.15.70.24"
MAIL_FROM = "mobile_money@microstrategy.com"
MAIL_TO_LIST = ""
MAIL_SUBJECT = ""
MAIL_SEND = ""
MAIL_SUPPORT_TO = ""
MAIL_SUPPORT_SUBJECT = "" 

################################# config params #################################


#convert a relative path to absolute
def resolve_path(relative_path, absolute_path = None):
    # if absolute path wasn't specified, use current dir instead.
    if not absolute_path:
        absolute_path = os.path.abspath(os.path.dirname(__file__))
    
    while (relative_path.startswith('../')):
        absolute_path = os.path.dirname(absolute_path)
        relative_path = relative_path[3:] 

    if (not relative_path.startswith('/')):
        relative_path = '/' + relative_path

    return absolute_path + relative_path

EMMA_ROOT = resolve_path("../../")
WEB_ROOT = resolve_path("../web")
LOG_ROOT = resolve_path("../../logs")
STATIC_ROOT = resolve_path("../../static")

MASTER_DBPOOL = PooledDB(oursql,
                         maxconnections = MASTER_MAX_CONN,
                         blocking = 1,
                         host = MASTER_DB_ADDR,
                         port = MASTER_DB_PORT,
                         user = MASTER_USER,
                         passwd = MASTER_PASSWD,
                         db = MASTER_DB_NAME,
                         use_unicode = False)

SLAVE_DBPOOL = PooledDB(oursql,
                        maxconnections = SLAVE_MAX_CONN,
                        blocking = 1,
                        host = SLAVE_DB_ADDR,
                        port = SLAVE_DB_PORT,
                        user = SLAVE_USER,
                        passwd = SLAVE_PASSWD,
                        db = SLAVE_DB_NAME,
                        use_unicode = False)

MEMCACHE_POOL = pylibmc.ThreadMappedPool(pylibmc.Client([MEMCACHE_ADDR]))
ONLINE_MEMCACHE_POOL = pylibmc.ThreadMappedPool(pylibmc.Client([ONLINE_MEMCACHE_ADDR]))
